package edu.nf.ch07.controller;

import edu.nf.ch07.service.PaymentService;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * @author wangl
 * @date 2025/4/29
 */
@Controller
public class PaymentController {

    /**
     * 注入一个map集合，spring容器会将此接口的所有实现类
     * 都注入到这个map中，key是bean的id，value是bean的实例
     */
    private Map<String, PaymentService> paymentServiceMap;

    public PaymentController(Map<String, PaymentService> paymentServiceMap) {
        this.paymentServiceMap = paymentServiceMap;
    }

    /**
     * 根据类型找出相应的支付策略实现来完成支付
     * @param type 支付类型
     */
    public void payment(String type) {
        PaymentService service = paymentServiceMap.get(type);
        service.payment();
    }
}